// <!-- 设置右侧标题随左侧导航而变换 -->
let pMsg = document.querySelector(".personalCenterMsg-div");
let oMsg = document.querySelector(".order-div");
let vMsg = document.querySelector(".vip-div");
let cMsg = document.querySelector(".coupon-div");
let clMsg = document.querySelector(".collect-div");
let hMsg = document.querySelector(".history-div");
let message = document.querySelector(".message-div");


let title = document.querySelector(".personal_tittle");

function nav_list_click(obj) {
    let a = obj.querySelector("a");
    title.innerHTML = a.innerHTML

//显示个人信息
    if (a.innerHTML == "基本信息") {
        pMsg.style.display = ''
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        getPersonalMessage()
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        message.style.display = 'none'
    } else if (a.innerHTML == "订单管理") {
        pMsg.style.display = 'none'
        oMsg.style.display = ''
        clMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        hMsg.style.display = 'none'
        message.style.display = 'none'
        getOrder();
    } else if (a.innerHTML == "我的收藏") {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        clMsg.style.display = ''
        hMsg.style.display = 'none'
        message.style.display = 'none'
        getCollect();
        // getCollect();
    } else if (a.innerHTML == "观影历史") {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = ''
        message.style.display = 'none'
        history();
    } else if (a.innerHTML == "会员") {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = ''
        cMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        message.style.display = 'none'

        memberStatus();
    } else if (a.innerHTML == "优惠券") {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        message.style.display = 'none'

        cMsg.style.display = ''
        getCoupon()
    } else if (a.innerHTML == "消息通知") {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        cMsg.style.display = 'none'

        message.style.display = ''
        getMessage();
    }
}

let str = ``;
let lookFlag = false;

function lookOldMessage(){

    let oldStr = "";

    $.ajax({
        type: 'get',
        url: serverConfig.serverUrl +'/devs/message/findByStatus',
        data:{userId:userInfo.id,status:0,pageNum:0,pageSize:100},
        async: false,//取消异步请求
        success: function (result) {
            let dateMessage = result.data.list;
            for(let i = 0; i < dateMessage.length;i++){
                oldStr += `
                <ul class="flow-default" id="LAY_demo6">
            <div>
                <div class="layui-row viewrow7">`;

                let arr = dateMessage[i].message.toString().split("{");
                if(dateMessage[i].type == 0){

                    // 您有一张{"+coupon.getMoney()+"}元的优惠券即将在{"+coupon.getUpdatedBy()+"}过期,请及时使用!

                    oldStr+=`
                            <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs3.png"><p>优惠券过期提醒</p><span>${dateMessage[i].createTime}</span><span>历史消息</span></div>

                        </div>
                        <div class="layui-row viewrow8">
                            <div class="layui-col-md12 warn-div"><p>您有一张<span>${arr[1]}</span>元的优惠券即将在<span>${arr[3]}</span>过期,请及时使用!</p></div>
                </div>
                    </div>
                </ul>`
                }else if(dateMessage[i].type == 1){
                    //"您有一张{10{元优惠券已过期";
                    oldStr+=`
                            <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs3.png"><p>优惠券过期提醒</p><span>${dateMessage[i].createTime}</span><span>历史消息</span></div>

                        </div>
                        <div class="layui-row viewrow8">
                            <div class="layui-col-md12 warn-div"><p>您有一张<span>${arr[1]}</span>元优惠券已过期</p></div>
                </div>
                    </div>
                </ul>`
                }
                else if(dateMessage[i].type == 2){
                    //String message = "您购买的电影: {坚如磐石{还有不到两小时就放映啦!请提前到场以免错过放映时间,感谢您的观看!";
                    oldStr+=`
                              <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs2.png"><p>电影即将开场提醒</p><span>${dateMessage[i].createTime}</span><span>历史消息</span></div>
                        </div>
                        <div class="layui-row viewrow8">
                               <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>还有不到两小时就放映啦!请提前到场以免错过放映时间,感谢您的观看!</p></div>
                        </div>
                    </div>
                </ul>`
                }
                else if(dateMessage[i].type == 3){
                    // String message = "您购买的电影票{坚如磐石{已支付成功,请关注场次座位信息和开场时间,祝您观影愉快!";
                    oldStr+=`
                            <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs4.png"><p>支付成功提醒</p><span>${dateMessage[i].createTime}</span><span>历史消息</span></div>
                        </div>
                        <div class="layui-row viewrow8">
                            <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>已支付成功,请关注场次座位信息和开场时间,祝您观影愉快!</p></div>

                        </div>
                    </div>
                </ul>`

                } 
                else if(dateMessage[i].type == 4){
                    // String message = "您购买的电影票{坚如磐石{支付失败,如有需要请重新购买!";
                    oldStr += `
                        <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs1.png"><p>支付失败提醒</p><span>${dateMessage[i].createTime}</span><span>历史消息</span></div>
                    </div>
                    <div class="layui-row viewrow8">
                        <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>支付失败,如有需要请重新购买!</p></div>
                    </div>
                </div>
            </ul>`
                }
            }
        }
    })
    document.getElementById("notLook").innerHTML = oldStr + str;
}

// 离开页面
window.addEventListener('beforeunload', function (e) {
    if(lookFlag){
        $.ajax({
            type: 'post',
            url: serverConfig.serverUrl +'/devs/message/updateByLookReal',
            data:{userId:userInfo.id},
        })
    }

})

function getMessage(){
    console.log(12)
    lookFlag = true;
    if(str == ""){
           //未查看
    $.ajax({
        type: 'get',
        url: serverConfig.serverUrl +'/devs/message/findByStatus',
        data:{userId:userInfo.id,status:1,pageNum:0,pageSize:100},
        async: false,//取消异步请求
        success: function (result) {
            
            if (result.code == 200) {
                let dateMessage = result.data.list;

                str += `<div id="lookOldMessage_div"><a onclick="lookOldMessage()">查看历史消息</a></div>`
                for(let i = 0; i < dateMessage.length;i++){
   
                    str += `
                    <ul class="flow-default" id="LAY_demo6">
                <div>
                    <div class="layui-row viewrow7">`;

                    let arr = dateMessage[i].message.toString().split("{");
                    if(dateMessage[i].type == 0){

                        // 您有一张{"+coupon.getMoney()+"}元的优惠券即将在{"+coupon.getUpdatedBy()+"}过期,请及时使用!

                        str+=`
                                <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs3.png"><p>优惠券过期提醒</p><span>${dateMessage[i].createTime}</span><span>新消息</span></div>

                            </div>
                            <div class="layui-row viewrow8">
                                <div class="layui-col-md12 warn-div"><p>您有一张<span>${arr[1]}</span>元的优惠券即将在<span>${arr[3]}</span>过期,请及时使用!</p></div>
                    </div>
                        </div>
                    </ul>`
                    }else if(dateMessage[i].type == 1){
                        //"您有一张{10{元优惠券已过期";
                        str+=`
                                <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs3.png"><p>优惠券过期提醒</p><span>${dateMessage[i].createTime}</span><span>新消息</span></div>

                            </div>
                            <div class="layui-row viewrow8">
                                <div class="layui-col-md12 warn-div"><p>您有一张<span>${arr[1]}</span>元优惠券已过期</p></div>
                    </div>
                        </div>
                    </ul>`
                    }
                    else if(dateMessage[i].type == 2){
                        //String message = "您购买的电影: {坚如磐石{还有不到两小时就放映啦!请提前到场以免错过放映时间,感谢您的观看!";
                        str+=`
                                  <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs2.png"><p>电影即将开场提醒</p><span>${dateMessage[i].createTime}</span><span>新消息</span></div>
                            </div>
                            <div class="layui-row viewrow8">
                                   <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>还有不到两小时就放映啦!请提前到场以免错过放映时间,感谢您的观看!</p></div>
                            </div>
                        </div>
                    </ul>`
                    }
                    else if(dateMessage[i].type == 3){
                        // String message = "您购买的电影票{坚如磐石{已支付成功,请关注场次座位信息和开场时间,祝您观影愉快!";
                        str+=`
                                <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs4.png"><p>支付成功提醒</p><span>${dateMessage[i].createTime}</span><span>新消息</span></div>
                            </div>
                            <div class="layui-row viewrow8">
                                <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>已支付成功,请关注场次座位信息和开场时间,祝您观影愉快!</p></div>

                            </div>
                        </div>
                    </ul>`

                    } 
                    else if(dateMessage[i].type == 4){
                        // String message = "您购买的电影票{坚如磐石{支付失败,如有需要请重新购买!";
                    str += `
                            <div class="layui-col-md12 msg-div"><img src="../imgs/icon/msgs1.png"><p>支付失败提醒</p><span>${dateMessage[i].createTime}</span><span>新消息</span></div>
                        </div>
                        <div class="layui-row viewrow8">
                            <div class="layui-col-md12 warn-div"><p>您购买的电影票<span>${arr[1]}</span>支付失败,如有需要请重新购买!</p></div>
                        </div>
                    </div>
                </ul>`
                    }
                }
                document.getElementById("notLook").innerHTML = str;
            } else {
                lookOldMessage();
            }
        }
    })
} else{
    document.getElementById("notLook").innerHTML = str;
}
}

let userInfo;
$(function () {

    document.getElementById("active_a").querySelector("i").setAttribute("style","padding-left: 10px;");
    $.ajax({
        headers: {
            "token": localStorage.getItem("token")
        },
        type: 'get',
        url: serverConfig.serverUrl +'/devs/user',
        async: false,//取消异步请求
        success: function (result) {
            if (result.code != 200) {
                // layer.msg('您还未登录', {icon: 2})
                localStorage.removeItem('token')
                window.location.href = '../html/login.html';
            } else {
                userInfo = result.data;
            }
        }
    })
    document.querySelector(".order-div").style.display = '';

    let sg = window.location.search.substr(0).split("=")[1];
    // console.log(sg)
    if (sg == null || sg == undefined || sg == 2) {
        message.style.display = 'none'
        pMsg.style.display = 'none'
        oMsg.style.display = ''
        clMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        hMsg.style.display = 'none'
        title.innerText = "订单管理"
        // document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('ddgl')[0].className = 'layui-nav-item nav_list layui-this'
        getOrder()
    } else if (sg == 1) {
        message.style.display = 'none'
        pMsg.style.display = ''
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        getPersonalMessage()
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('jbxs')[0].className = 'layui-nav-item nav_list layui-this'
        title.innerText = "基本信息"
    } else if (sg == 3) {
        message.style.display = 'none'
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        clMsg.style.display = ''
        hMsg.style.display = 'none'
        getCollect();
        title.innerText = "我的收藏"
        document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('wdsc')[0].className = 'layui-nav-item nav_list layui-this'
    } else if (sg == 4) {
        message.style.display = 'none'
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        cMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = ''
        history();
        title.innerText = "观影历史"
        document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('gyls')[0].className = 'layui-nav-item nav_list layui-this'
    } else if (sg == 5) {
        message.style.display = 'none'
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        cMsg.style.display = ''
        getCoupon()
        title.innerText = "优惠券"
        document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('yhq')[0].className = 'nav_list layui-this'
    }else if (sg == 6) {
        pMsg.style.display = 'none'
        oMsg.style.display = 'none'
        vMsg.style.display = 'none'
        clMsg.style.display = 'none'
        hMsg.style.display = 'none'
        cMsg.style.display = 'none'
        message.style.display = ''
        getMessage()
        title.innerText = "消息通知"
        document.getElementsByClassName('layui-this')[0].className = 'layui-nav-item nav_list'
        document.getElementsByClassName('xttz')[0].className = 'nav_list layui-this'
    }
})

//从后台获取个人信息
function getPersonalMessage() {
    $("#nickname").val(userInfo.nickname);
    $("#ID-laydate-demo").val(userInfo.birthday);
    $("#area").val(userInfo.area);
    $("#signature").val(userInfo.signature);
    $('#ID-upload-demo-img').attr("src", "../imgs/img-personal/avatar.png");

    let sexs = document.getElementsByName("sex");
    let statu = document.getElementsByName("status");
    let hobby = document.getElementsByName("interest[]");

    let arr = userInfo.hobby.split(",")[0].split(" ");
    //console.log(userInfo.hobby.split(","))//得到一个集合数组
    //勾选性别
    if (userInfo.sex == "0") {
        sexs[0].checked = true;
        sexs[1].checked = false;
    } else {
        sexs[0].checked = false;
        sexs[1].checked = true;
    }
//勾选状态
    if (userInfo.status == "已婚") {
        statu[0].checked = true;
        statu[1].checked = false;
        statu[2].checked = false;
        statu[3].checked = false;
    } else if (userInfo.status == "未婚") {
        statu[0].checked = false;
        statu[1].checked = true;
        statu[2].checked = false;
        statu[3].checked = false;
    } else if (userInfo.status == "单身") {
        statu[0].checked = false;
        statu[1].checked = false;
        statu[2].checked = true;
        statu[3].checked = false;
    } else if (userInfo.status == "热恋") {
        statu[0].checked = false;
        statu[1].checked = false;
        statu[2].checked = false;
        statu[3].checked = true;
    }
//勾选爱好
    for (let i = 0; i < arr.length; i++) {
        // console.log(arr[i])
        for (let j = 0; j < hobby.length; j++) {

            if (arr[i] == hobby[j].getAttribute("value")) {
                // console.log(0)
                hobby[j].checked = true;
            }
        }
    }
}

//从输入框拿发送到后台
function getFromInfo() {
    let nickname = document.querySelector('#nickname').value;//获得昵称
    let birthday = document.querySelector('#ID-laydate-demo').value;//获得生日
    let area = document.querySelector('#area').value;//获得地区
    let signature = document.querySelector('#signature').value;//获得个性签名
    let sexs = document.getElementsByName("sex");
    let sta = document.getElementsByName("status");
    let hobbys = document.getElementsByName("interest[]");
    let avatarurl = document.getElementsByClassName("layui-upload-img")[0].src

    let sex;//获得性别
    let statu;//获得状态
    let hobbies = '';//获得爱好
    //性别选中
    if (sexs[0].checked) {
        sex = sexs[0].getAttribute("value");
    } else if (sexs[1].checked) {
        sex = sexs[1].getAttribute("value");
    }

    //状态选中
    if (sta[0].checked) {
        statu = sta[0].getAttribute("value");
    } else if (sta[1].checked) {
        statu = sta[1].getAttribute("value");
    } else if (sta[2].checked) {
        statu = sta[2].getAttribute("value");
    } else if (sta[3].checked) {
        statu = sta[3].getAttribute("value");
    }
    //爱好选中

    for (let i = 0; i < hobbys.length; i++) {
        if (hobbys[i].checked) {
            hobbies += hobbys[i].getAttribute("value") + " ";
            // console.log(hobbies)
        }
    }
    // console.log(birthday)
    $.ajax({
        type: 'post',
        url: serverConfig.serverUrl +'/devs/user/updataUser',
        data: {
            id: userInfo.id,
            nickname: nickname,
            birthday: birthday,
            sex: sex,
            area: area,
            status: statu,
            hobby: hobbies,
            signature: signature,
            avatarUrl: avatarurl
        },
    })
}

let orderData;
function getOrder() {
    // console.log(2)
    layui.use('flow', function () {
        var flow = layui.flow;

        flow.load({
            elem: '#LAY_demo1' //流加载容器
            ,
            scrollElem: '#aa' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,
            done: function (page, next) {
                let lis = [];

                setTimeout(function () {
                    let orderPageSize;
                    let orderPagePages;

                    $.ajax({
                        type: 'get',
                        url:serverConfig.serverUrl + '/devs/order',
                        data: {userId: userInfo.id, pageNum: page, pageSize: 3},
                        async: false,
                        success: function (result) {
                            // console.log(result)
                            if (result.code == 200) {
                                orderPageSize = result.pageSize;
                                orderPagePages = result.pagePages;
                                orderData = result.data;
                            } else {
                                console.log(result)
                            }
                        }
                    })

                    for (let i = 0; i < orderPageSize; i++) {
                        lis.push(`<div><div class="layui-row viewrow1">
                    <div class="layui-col-md2 time-div"><p>${orderData[i].createTime.split(" ")[0]}</p></div>
                    <div class="layui-col-md4 number-div"><p>票无忧订单号:${orderData[i].number}</p></div>
                    <div class="layui-col-md2 layui-col-md-offset4"><img src="../imgs/icon/delete6.png" onclick="del(${orderData[i].id},this)"></div>
                </div>
                <div class="layui-row viewrow2">
                    <div class="layui-col-md2 viewPicture-div"><img src="../imgs/movie-img/${orderData[i].posterImg}"></div>
                    <div class="layui-col-md3 viewContent-div">
                        <div class="layui-row title-div"><p>《${orderData[i].movieTitle}》</p></div>
                        <div class="layui-row name-div"><p>票无忧影城</p ></div>`);
                        if(orderData[i].sessionId == 1){
                            lis.push(`<div class="layui-row seat-div"><p>巨幕影院`);
                        }else{
                            lis.push(`<div class="layui-row seat-div"><p>激光6厅`);
                        }
                        let seatArr = '';
                        let seatIds = [];
                        seatIds.push(orderData[i].seatId + '');
                        $.ajax({
                            type: 'get',
                            url: serverConfig.serverUrl +`/devs/seat/${seatIds}`,
                            async: false,//取消异步请求
                            success: function (result) {
                                if (result.code == 200) {
                                    seatArr = result.data;
                                } else {
                                    console.log(result)
                                }
                            }
                        })
                        for (let i = 0; i < seatArr.length; i++) {
                            if (i != seatArr.length - 1) {
                                lis.push(`${seatArr[i].seatRow}排${seatArr[i].seatColumn}座,`)
                            } else {
                                lis.push(`${seatArr[i].seatRow}排${seatArr[i].seatColumn}座 `)
                            }
                        }
                        lis.push(`</p></div>
                        <div class="layui-row date-div"><p>${orderData[i].startTime}</p></div>
                    </div>
                    <div class="layui-col-md2 layui-col-md-offset2 viewcoin-div"><p><img
                            src="../imgs/icon/money-yuan.png">${orderData[i].total}</p></div>`);
                        if (orderData[i].status == 0) {
                            lis.push(`<div class="layui-col-md1 status-div"><p>待支付</p></div>`);
                        } else if (orderData[i].status == 1) {
                            lis.push(`<div class="layui-col-md1 status-div"><p>已付款</p></div>`);
                        } else if (orderData[i].status == 2) {
                            lis.push(`<div class="layui-col-md1 status-div"><p>支付失败</p></div>`);
                        }else if (orderData[i].status == 10) {
                            lis.push(`<div class="layui-col-md1 status-div"><p>已退款</p ></div>`);
                        }else if (orderData[i].status == 3) {
                            lis.push(`<div class="layui-col-md1 status-div"><p>请留意放映时间</p ></div>`);
                        }
                        lis.push(`<div class="layui-col-md2 payfor-div">
                        <div class="layui-row">`);
                        if (orderData[i].status == 0) {
                            lis.push(`<button type="button" class="btn-pay" onclick="toBuy(${orderData[i].id})">去付款</button>`);
                        } else if (orderData[i].status == 1){
                            lis.push(`<button type="button" class="btn-pay" onclick="cancelOrder(${orderData[i].id})">退/换票</button>`);
                        }else if (orderData[i].status == 10){
                            lis.push(`<button type="button" class="btn-pay" >已退款</button>`);
                        }else if (orderData[i].status == 3) {
                            lis.push(`<button type="button" class="btn-pay" >即将放映</button>`);
                        }
                        lis.push(`</div>
                        <div class="layui-row detail-div"><p>查看详情</p></div>
                    </div>
                </div></div>`)
                    }
                    next(lis.join(''), page < orderPagePages);
                }, 500);
            }
        })
    })
}

// 去付款
// 去付款
function toBuy(orderId,number) {
        let order = null;
        $.ajax({
            type: 'get',
            url: serverConfig.serverUrl +`/devs/order/${orderId}`,
            async: false,//异步加载
            success: function (reulst) {
                if (reulst.code == 200) {
                    order = reulst.data;
                    $.ajax({
                        type: 'get',
                        url: serverConfig.serverUrl +`/devs/alipay/conPayTicket`,
                        data: {orderNum: order.number},
                        success: function (alipayRedirectHtml) { // 创建一个新的div元素
                            var div = document.createElement("div"); // 将后台返回的支付宝支付页面的HTML内容赋值给div的
                            div.innerHTML = alipayRedirectHtml; // 获取div中的form元素
                            var form = div.querySelector("form"); // 将form添加到文档中
                            document.body.appendChild(form); // 提交form表单，实现页面跳转到支付宝支付页面
                            form.submit();
                        }
                    })
                } else {
                    collectPageInfo = []
                    console.log(reulst)
                }
            }
        })
    
        
    }

//退票
function cancelOrder(orderId) {
    let order = null;
    $.ajax({
        type: 'get',
        url: serverConfig.serverUrl +`/devs/order/${orderId}`,
        async: false,//异步加载
        success: function (reulst) {
            if (reulst.code == 200) {
                order = reulst.data;
            } else {
                collectPageInfo = []
            }
        }
    })
    if (order.status == 3){
        layer.msg('电影即将放映,当前无法退票!', {icon: 2})
        return
    }

    $.ajax({
        type: 'get',
        url:serverConfig.serverUrl + `/devs/alipay/refund`,
        data:{orderNum:order.number},
        async: false,//异步加载
        success: function (reulst) {
            if(reulst.code == 200){
                window.location='/html/personal_center.html'
            }else if(result.code == 500){
                layer.msg("退款失败，请重新尝试！")
            }
        }
    })

}
// 获取我的收藏信息
function getCollect() {
    layui.use('flow', function () {
        var flow = layui.flow;

        flow.load({
            elem: '#LAY_demo2' //流加载容器
            ,
            scrollElem: '#a' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,
            done: function (page, next) { //执行下一页的回调
                let lis = [];

                //模拟数据插入
                setTimeout(function () {
                    let collectPageInfo;
                    let collectData;

                    $.ajax({
                        type: 'get',
                        url: serverConfig.serverUrl +'/devs/movie/lookCollect',
                        data: {userId: userInfo.id, pageNum: page, pageSize: 3},
                        async: false,//异步加载
                        success: function (reulst) {
                            if (reulst.code == 200) {
                                collectPageInfo = reulst.data;
                                console.log(collectPageInfo),
                                    collectData = collectPageInfo.list;
                            } else {
                                collectPageInfo = []
                                console.log(reulst)
                            }
                        }
                    })

                    for (let i = 0; i < collectPageInfo.size; i++) {
                        lis.push(`
                        <div>
                                <div class="layui-row viewro1">`)
                        if (collectData[i].startTime != null) {
                            lis.push(`<div class="layui-col-md2 time-div"><p>${collectData[i].startTime}</p></div>`)
                        } else {
                            lis.push(`<div class="layui-col-md2 time-div"><p>暂无最近场次</p></div>`)
                        }
                        lis.push(`
                                
                                <div class="layui-col-md2 layui-col-md-offset4">
                                    <img src="../imgs/icon/xinxins.png" onclick="del(${collectData[i].id},this)">
                                </div>
                            </div>
                            <div class="layui-row viewro2">
                            <div class="layui-col-md2 viewPicture-div">
                                <img src="../imgs/movie-img/${collectData[i].posterImg}">
                            </div>
                            <div class="layui-col-md3 viewContents-div">
                                <div class="layui-row title-div">
                                    <p>《${collectData[i].movieTitle}》</p>
                                </div>
                             <div class="layui-row names-div"><p>票无忧影城</p></div>
                        <div class="layui-row languages-div"><p>language: ${collectData[i].language}</p></div>
                        <div class="layui-row director-div"><p>导演: ${collectData[i].director}</p></div>
                        <div class="layui-row score-div"><p>评分: ${collectData[i].score}</p></div>
                        </div>
                            <div class="layui-col-md2 payfor-div">
                                <div class="layui-row details-div">
                                    <p>查看详情</p>
                                </div>
                            </div>
                        </div>
                        </div> `)
                    }
                    //执行下一页渲染，第二参数为：满足“加载更多”的条件，即后面仍有分页
                    //pages为Ajax返回的总页数，只有当前页小于总页数的情况下，才会继续出现加载更多
                    next(lis.join(''), page < collectPageInfo.pages); //假设总页数为 10
                }, 500);
            }
        });
    });
}

//获取我的观影历史
function history() {
    layui.use('flow', function () {
        var flow = layui.flow;
        flow.load({
            elem: '#LAY_demo4' // 流加载容器
            ,
            scrollElem: '#aabb' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,
            done: function (page, next) {
                let lis = [];
                setTimeout(function () {
                    let historyPageInfo;
                    let historyData;

                    $.ajax({
                        type: 'get',
                        url: serverConfig.serverUrl +'/devs/movie/lookHistory',
                        data: {userId: userInfo.id, pageNum: page, pageSize: 3},
                        async: false,
                        success: function (result) {
                            console.log(result)
                            if (result.code == 200) {
                                historyPageInfo = result.data;
                                historyData = historyPageInfo.list;
                            } else {
                                historyPageInfo = []
                                console.log(result)
                            }
                        }
                    })
                    let pages;
                    if (historyPageInfo != null && historyPageInfo != undefined) {
                        pages = historyPageInfo.pages
                    } else {
                        pages = 1;
                    }
                    if (historyData == undefined || historyData == null) {
                        lis.push(`<div class="null-div"><p>暂无观影历史!请关注票无忧影城更多电影!~</p></div>`)
                    } else {
                        console.log(historyData)
                        for (let i = 0; i < historyData.length; i++) {
                            lis.push(`<div>
                            <div class="layui-row viewrow5">
                                <div class="layui-col-md6 histories-div"><p><img src="../imgs/icon/gyls.png">${historyData[i].movieTittle}</p></div>
                                <div class="layui-col-md3 layui-col-md-offset3 scores-div"><p><img src="../imgs/icon/score1.png">${historyData[i].score}分<p></div>
                            </div>
                            <div class="layui-row viewrow6">
                                <div class="layui-col-md3 synopsis-div">
                                    <div class="layui-row posterImg-div"><img src="../imgs/movie-img/${historyData[i].posterImg}"></div>
                                </div>
                                <div class="layui-col-md1 layui-col-md-offset1 xian-div">
                                    <div class="layui-row longTime-div"><p>时长: <span>${historyData[i].duration}分</span></p></div>
                                    <div class="layui-row directors-div"><p>导演: <span>${historyData[i].director}</span></p></div>
                                </div>
                            </div>
                        </div>`)
                        }
                    }
                    next(lis.join(''), page < pages);
                }, 500);
            }
        })
    })
}

//查询优惠券
function getCoupon() {
    layui.use('flow', function () {
        var flow = layui.flow;
        flow.load({
            elem: '#LAY_demo3' //流加载容器
            ,
            scrollElem: '#aaa' //滚动条所在元素，一般不用填，此处只是演示需要。
            ,
            done: function (page, next) {
                let lis = [];
                setTimeout(function () {
                    let couponPageInfo;
                    let couponData;

                    $.ajax({
                        type: 'get',
                        url:serverConfig.serverUrl +'/devs/coupon/findByUserId',
                        data: {userId: userInfo.id, pageNum: page, pageSize: 3},
                        async: false,
                        success: function (result) {
                            if (result.code == 200) {
                                couponPageInfo = result.data;
                                couponData = couponPageInfo.list;
                            } else {
                                couponPageInfo = []
                            }
                        }
                    })
                    let pages
                    if (couponPageInfo != null && couponPageInfo != undefined) {
                        pages = couponPageInfo.pages
                    } else {
                        pages = 1;
                    }


                    console.log(couponPageInfo)
                    if (couponData == undefined || couponData == null) {
                        lis.push(`<div class="null-div"><p>暂无优惠券!请关注票无忧影城更多活动~</p></div>`)
                    } else {
                        for (let i = 0; i < couponData.length; i++) {
                            lis.push(`<div>
                        <div class="layui-row viewrow3">
                            <div class="layui-col-md4 yhq-div"><img src="../imgs/icon/yhq.png"></div>
                            <div class="layui-col-md3 layui-col-md-offset5 hott-div"><img src="../imgs/icon/hott.png"></div>
                        </div>
                        <div class="layui-row viewrow4">
                            <div class="layui-col-md2 quan-div"><img src="../imgs/icon/quan.png"></div>
                            <div class="layui-col-md3 layui-col-md-offset1 content-div">
                                <div class="layui-row pwyyhq-div"><p>票无忧优惠券</p></div>
                    <div class="layui-row deadline-div"><p><span>${couponData[i].updatedBy}</span>到期</p></div>
                                <div class="layui-row role-div"><p>规则:<span>${couponData[i].illustrate}</span></p></div>
                            </div>
                            <div class="layui-col-md2 explain-div"><p>此优惠券解释权归票无忧影城所属</p></div>
                            <div class="layui-col-md3 layui-col-md-offset1 money-div">`)

                            if (couponData[i].status == 0) {
                                lis.push(`<div class="layui-row par-div"><p><span>${couponData[i].money}</span>元</p><img src="../imgs/icon/wsy.png"></div>
                                            <div class="layui-row pare-div"><p>未使用</p></div>
                            </div>
                        </div>
                                </div>`)
                            } else if (couponData[i].status == 1) {
                                lis.push(`<div class="layui-row par-div"><p><span>${couponData[i].money}</span>元</p><img src="../imgs/icon/uus.png"></div>
                                            <div class="layui-row pare-div"><p>已使用</p></div>
                            </div>
                        </div>
                                </div>`)
                            } else if (couponData[i].status == 2) {
                                lis.push(`<div class="layui-row par-div"><p><span>${couponData[i].money}</span>元</p><img src="../imgs/icon/gqq.png"></div>
                                            <div class="layui-row pare-div"><p>已过期</p></div>
                            </div>
                        </div>
                                </div>`)
                            }
                        }
                    }
                    next(lis.join(''), page < pages);
                }, 500);
            }
        })
    })
}

//删除订单
function del(orderId, obj) {
    $.ajax({
        type: 'delete',
        url: serverConfig.serverUrl +'/devs/order',
        data: {id: orderId, userId: userInfo.id},
        success: function (result) {
            let str = ''
            if (result.code != 200) {

            } else {
                let order = obj.parentElement.parentElement.parentElement;

                order.innerHTML = str;
                layer.msg("删除成功！");
            }
        }
    })
}

// 删除前段优惠券样式
function delById(obj) {
    let id = obj.getAttribute('data-id')
    $.ajax({
        type: 'post',
        url: serverConfig.serverUrl +`/devs/coupon/delById/${id}`,
        success: function (result) {
            if (result.code == 200) {
                $(obj.parentNode.parentNode).remove()
            }
        }
    })
}

function memberStatus() {
    let id = userInfo.id
    $.ajax({
        type: 'get',
        url: serverConfig.serverUrl +`/devs/member/findByUserId/${id}`,
        success: function (result) {
            let data = result.data;
            let time = data.expirationTime;
            let time2 = data.openTime;
            let openTime = parseInt(time2.slice(0, 4), 10).toString() + "年" + parseInt(time2.slice(5, 7), 10).toString() + "月" + parseInt(time2.slice(8, 10), 10).toString() + "日";
            let expirationTime = parseInt(time.slice(0, 4), 10).toString() + "年" + parseInt(time.slice(5, 7), 10).toString() + "月" + parseInt(time.slice(8, 10), 10).toString() + "日";
            if (result.code == 500) {
                document.getElementsByClassName("nullvip")[0].style.display = "block";
                document.getElementsByClassName("vip-time")[0].style.display = "none";
            } else if (result.code == 505) {
                let str = `<thead>
                        <tr>
                            <th>状态</th>
                            <th>开通时间</th>
                            <th>截止时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><span class="vip-begin-time">已过期</span></td>
                            <td><span class="vip-begin-time">${openTime}</span></td>
                            <td><span class="vip-end-time">${expirationTime}</span></td>
                            <td><a onclick="reopen()" class="buy-btn vip" href="../html/vip.html">重新开通会员</a></td>
                        </tr>
                    </tbody>`;
                document.getElementById("vip-table").innerHTML = str;
            } else {
                let str = `<thead>
                        <tr>
                            <th>开通时间</th>
                            <th>截止时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><span class="vip-begin-time">${openTime}</span></td>
                            <td><span class="vip-end-time">${expirationTime}</span></td>
                            <td><a onclick="renew()" class="buy-btn vip" href="../html/vip.html">续费会员</a></td>
                        </tr>
                    </tbody>`;
                document.getElementById("vip-table").innerHTML = str;
            }
        }
    })
}




